package br.com.android.pubclub.web;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import br.com.android.pubclub.R;
import br.com.android.pubclub.basicas.Cliente;
import br.com.android.pubclub.dados.WsServicos;

public class Login extends Activity {
	
	EditText edtLogin, edtSenha;
	
	String login, senha, retorno;
	public static Cliente clienteLogado;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        
        edtLogin = (EditText) findViewById(R.id.editTextLogin);
		edtSenha = (EditText) findViewById(R.id.editTextSenha);
        
     // Obtendo a ultimo login digitado
     		SharedPreferences preferencias = getSharedPreferences("configuracao",
     				MODE_PRIVATE);
     		String logincache = preferencias.getString("login_cache", "");
     		edtLogin.setText(logincache);
        
    }
    
	@Override
	protected void onDestroy() {
		super.onDestroy();
		// Salva a login para utiliza-la quando essa tela for re-aberta
		SharedPreferences preferencias = getSharedPreferences("configuracao",
				MODE_PRIVATE);
		SharedPreferences.Editor editor = preferencias.edit();
		editor.putString("login_cache", edtLogin.getText().toString());
		editor.commit();
	}

    public void realizarLogin(View v)
    {

		login = edtLogin.getText().toString();
		senha = edtSenha.getText().toString();
		
		Intent it = new Intent(this, WsServicos.class);
		it.putExtra("parametro", "realizarLogin");
		it.putExtra("login", edtLogin.getText().toString());
		it.putExtra("senha", edtSenha.getText().toString());
		startActivity(it);

		finish();

    }
    
    public void cadastrarCliente(View v)
    {
		
		Intent it = new Intent(this, CadastraCliente.class);
		it.putExtra("parametro", "cadastarCliente");
		startActivity(it);
		
		finish();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.login, menu);
        return true;
    }
    
}
